﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

namespace EzFrameWork
{
    /// <summary>
    /// 单例模板练习
    /// </summary>
    public class EzSenceManager : Singleton<EzSenceManager>
    {
        /// <summary>
        /// 同步加载场景
        /// </summary>
        public void LoadScence(string name, UnityAction fuc)
        {
            SceneManager.LoadScene(name);
            fuc();
        }

        ///<summary>
        ///异步加载场景
        ///<summary>
        public void AsyLoadScence(string name, UnityAction fuc,UnityAction<float> progress)
        {
            EzMonoManager.Instance.StartCoroutine(LoadScenceAsy(name,fuc,progress));
        }
        public void AsyLoadScence(string name, UnityAction fuc)
        {
            EzMonoManager.Instance.StartCoroutine(LoadScenceAsy(name, fuc));
        }

        IEnumerator LoadScenceAsy(string name, UnityAction fuc,UnityAction<float> progress)
        {
            AsyncOperation ao = SceneManager.LoadSceneAsync(name);
            while (!ao.isDone)
            {
                progress(ao.progress);
                yield return ao;
            }
            fuc();
        }

        IEnumerator LoadScenceAsy(string name, UnityAction fuc)
        {
            AsyncOperation ao = SceneManager.LoadSceneAsync(name);
            while (!ao.isDone)
            {
                yield return ao;
            }
            fuc();
        }

        
    }
}

